package xd.ylwy.indicators.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import xd.ylwy.indicators.entity.Average;
import xd.ylwy.indicators.entity.StudentNum;
import xd.ylwy.indicators.entity.TbIndicators;
import xd.ylwy.indicators.entity.WarningStudent;
import xd.ylwy.indicators.mapper.TbIndicatorsMapper;
import xd.ylwy.indicators.service.ITbIndicatorsService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author xd
 * @since 2022-09-23
 */
@Service
public class TbIndicatorsServiceImpl extends ServiceImpl<TbIndicatorsMapper, TbIndicators> implements ITbIndicatorsService {
    @Autowired
    private TbIndicatorsMapper tbIndicatorsMapper;
    public List<Map<String, Object>> warningFaculty(){
        return tbIndicatorsMapper.warningFaculty();
    }
    public List<Map<String, Object>> warningGrade(){
        return tbIndicatorsMapper.warningGrade();
    }

    public List<Map<String, Object>> warningIntervene(){ return tbIndicatorsMapper.warningIntervene(); }
    public Average average(){ return tbIndicatorsMapper.average(); }

    public StudentNum studentNum(){
        StudentNum studentNum = new StudentNum();
        studentNum.setWarningStudentNum(tbIndicatorsMapper.warningStudentNum());
        studentNum.setInterveneStudentNum(tbIndicatorsMapper.interveneStudentNum());
        studentNum.setStudentNum(tbIndicatorsMapper.studentNum());
        studentNum.setWarningRate(studentNum.getWarningStudentNum()/studentNum.getStudentNum());
        studentNum.setInterveneRate(studentNum.getInterveneStudentNum()/studentNum.getStudentNum());
        return studentNum;
    }
    public TbIndicators selectByID(String id){
        return tbIndicatorsMapper.selectByID(id);
    }

    public Boolean updateText(TbIndicators tbIndicators) {
        return tbIndicatorsMapper.updateText(tbIndicators);
    }

    public List<WarningStudent> warningStudent(){
        Average average = tbIndicatorsMapper.average();
        List<WarningStudent> warningStudents = tbIndicatorsMapper.warningStudent();
        for (WarningStudent warningStudent:warningStudents){
            warningStudent.setName(warningStudent.getName().replaceAll("(?<=[\\u4e00-\\u9fa5]{1})[\\u4e00-\\u9fa5]", "*"));
            warningStudent.setId(warningStudent.getId().replaceAll("(?<=\\w{3})\\w", "*"));
            if (warningStudent.getAcademic()<average.getAcademic()){
                warningStudent.setText(warningStudent.getText()+"学业预警 ");
            }
            if (warningStudent.getSleep()<average.getSleep()){
                warningStudent.setText(warningStudent.getText()+"睡眠预警 ");
            }
            if (warningStudent.getRead()<average.getRead()){
                warningStudent.setText(warningStudent.getText()+"阅读预警 ");
            }
            if (warningStudent.getRelationship()<average.getRelationship()){
                warningStudent.setText(warningStudent.getText()+"人际关系预警 ");
            }
            if (warningStudent.getPhysical()<average.getPhysical()){
                warningStudent.setText(warningStudent.getText()+"身体素质预警 ");
            }
            if (warningStudent.getCommunity()<average.getCommunity()){
                warningStudent.setText(warningStudent.getText()+"社团活跃度预警 ");
            }
        }
        return warningStudents;
    }
}
